package we3d.core.culling 
{
	import we3d.mesh.Vertex;
	
	public class BoundBox extends BoundSphere
	{
		public function BoundBox () {}
		
		public var minx:Number=2147483647;
		public var miny:Number=2147483647;
		public var minz:Number=2147483647;
		
		public var maxx:Number=-2147483647;
		public var maxy:Number=-2147483647;
		public var maxz:Number=-2147483647;
		
		public var points:Array = [	new Vertex(),new Vertex(),new Vertex(),new Vertex(), new Vertex(),new Vertex(),new Vertex(),new Vertex() ];
		
		public override function reset () :void {
			
			super.reset();
			
			minx = 2147483647;
			miny = minx;
			minz = minx;
			
			maxx = -minx;
			maxy = maxx;
			maxz = maxx;
		}
		
		public override function testPoint (x:Number, y:Number, z:Number) :void {
			
			if(x < minx) minx = x;
			if(y < miny) miny = y;
			if(z < minz) minz = z;
			
			if(x > maxx) maxx = x;
			if(y > maxy) maxy = y;
			if(z > maxz) maxz = z;
			
			var cx:Number = (maxx + minx)/2;
			var cy:Number = (maxy + miny)/2;
			var cz:Number = (maxz + minz)/2;
			
			var dx:Number = maxx-cx;
			var dy:Number = maxy-cy;
			var dz:Number = maxz-cz;
			
			boundingSphere = Math.sqrt(dx*dx + dy*dy + dz*dz);
			
			points[0].assign(minx, miny, minz);
			points[6].assign(maxx, maxy, maxz);
			points[1].assign(maxx, miny, minz);
			points[2].assign(maxx, maxy, minz);
			points[3].assign(minx, maxy, minz);
			points[4].assign(minx, miny, maxz);
			points[5].assign(maxx, miny, maxz);
			points[7].assign(minx, maxy, maxz);
		}
	}
}